package org.csu.mypetstore.service;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.persistence.AccountDAO;
import org.csu.mypetstore.persistence.impi.AccountDAOImpi;

public class AccountService {
    private AccountDAO accountDAO;
    public AccountService(){
        accountDAO = new AccountDAOImpi();
    }
    public Account AccountLogon(Account account) {
        return accountDAO.getAccountByUsernameAndPassword(account);
    }

    public Account getAccount(String username,String password){

        return accountDAO.getAccountByUsername(username);
    }
    //注册账号
    public void insertAccount(Account account) {
        accountDAO.insertAccount(account);
        accountDAO.insertProfile(account);
        accountDAO.insertSignOn(account);
    }
//    更新用户的信息
    public void updateAccount(Account account){
        accountDAO.updateAccount(account);
        accountDAO.updateProfile(account);

        if(account.getPassword() != null && account.getPassword().length()>0){
            accountDAO.updateSignOn(account);
        }
    }
}
